home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 0362 / bcsdk.zip / TESTDDE.C < prev    next >
C/C++ Source or Header  |  1995-04-01  |  4KB  |  179 lines

  1. /*
  2.     BarClock(tm) v2.4
  3.  
  4.     Copyright (c) 1993  Patrick Breen
  5.     All rights reserved.
  6.  
  7.     How to reach me:
  8.  
  9.         Patrick Breen
  10.         PO Box 523
  11.         Medford, MA 02155
  12.  
  13.         Phone    (617) 396-2673
  14.         Fax        (617) 396-5761
  15.  
  16.         Internet:        pbreen@world.std.com
  17.         CompuServe:     70312,743
  18.         AmericaOnline:    PBreen
  19. */
  20.  
  21. #include "bcddelib.h"
  22.  
  23. LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  24.  
  25. HINSTANCE hAppInstance;        // Application instance
  26.  
  27. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  28.                 LPSTR lpCmd, int nCmdShow)
  29. {
  30.     WNDCLASS wndClass;
  31.     HWND hWnd;
  32.     DWORD style;
  33.     MSG msg;
  34.  
  35.     // We can only have one instance running
  36.     if (hPrevInstance != (HINSTANCE) 0)
  37.         return (0);
  38.  
  39.     // Set the global and resource instance
  40.     hAppInstance = hInstance;
  41.  
  42.     // Define the bar window class
  43.     wndClass.style        = 0;
  44.     wndClass.cbClsExtra       = 0;
  45.     wndClass.cbWndExtra    = 0;
  46.     wndClass.hIcon        = NULL;
  47.     wndClass.hCursor        = LoadCursor(0, IDC_ARROW);
  48.     wndClass.lpszMenuName  = NULL;
  49.     wndClass.lpfnWndProc   = WndProc;
  50.     wndClass.hInstance     = hInstance;
  51.     wndClass.hbrBackground = (HBRUSH) (COLOR_BACKGROUND + 1);
  52.     wndClass.lpszClassName = "TestApp";
  53.  
  54.     // Register the window class
  55.     if (RegisterClass(&wndClass)) {
  56.  
  57.         // Setup the window style
  58.         style = WS_POPUP | WS_BORDER | WS_CAPTION | WS_THICKFRAME | WS_VISIBLE | WS_SYSMENU;
  59.  
  60.         // Create the bar window
  61.         hWnd = CreateWindow("TestApp", "TestApp", style,
  62.                         0, 0, 100, 50,
  63.                         NULL, LoadMenu(hInstance, MAKEINTRESOURCE(100)),
  64.                         hInstance, NULL);
  65.  
  66.         // If we could create the app window
  67.         if (hWnd) {
  68.  
  69.               BCDdeLibInit();
  70.  
  71.             // Start the message loop
  72.             while (GetMessage(&msg, (HWND) 0, 0, 0)) {
  73.                 TranslateMessage(&msg);
  74.                 DispatchMessage(&msg);
  75.             }
  76.  
  77.             BCDdeLibFree();
  78.         }
  79.  
  80.         // All done with the class
  81.         UnregisterClass("TestApp", hInstance);
  82.     }
  83.  
  84.     // Return something
  85.     return (msg.wParam);
  86. }
  87.  
  88. LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  89. {
  90.     char hostBuf[128];
  91.  
  92.     switch (msg) {
  93.  
  94.         case WM_COMMAND:
  95.             // If this is a command
  96.             // (either from the menu or one
  97.             //  that we sent to ourselves)
  98.             if (HIWORD(lParam) == 0) {
  99.  
  100.                 // Switch on menu ID
  101.                 switch (wParam) {
  102.  
  103.                     case 100:
  104.                         BCDdeMessage("This is a DDE message!", 0);
  105.                         break;
  106.  
  107.                     case 101:
  108.                         BCDdeCalendar(1995, 5, 8);
  109.                         break;
  110.  
  111.                     case 102:
  112.                         BCDdePlayWave("tada.wav");
  113.                         break;
  114.  
  115.                     case 103:
  116.                         BCDdeRunApp("notepad.exe");
  117.                         break;
  118.  
  119.                     case 110:
  120.                         BCDdeTimerAdd("Test Timer",
  121.                                     eTmrCountUp,
  122.                                     5, 50,
  123.                                     eIncMinute,
  124.                                     0);
  125.                         break;
  126.  
  127.                     case 111:
  128.                         BCDdeTimerDelete("Test Timer");
  129.                         break;
  130.  
  131.                     case 112:
  132.                         BCDdeTimerStart("Test Timer");
  133.                         break;
  134.  
  135.                     case 113:
  136.                         BCDdeTimerStop("Test Timer");
  137.                         break;
  138.  
  139.                     case 120:
  140.                         BCDdeAlarmAdd("Test Alarm",
  141.                                     1995, 5, 8,
  142.                                     12, 0,
  143.                                     eRepeatHour);
  144.                         break;
  145.  
  146.                     case 121:
  147.                         BCDdeAlarmDelete("Test Alarm");
  148.                         break;
  149.  
  150.                     case 140:
  151.                         if (BCDdeQueryHost(hWnd, hostBuf, sizeof(hostBuf)) == BCDDE_NOERROR) {
  152.                             BCDdeSetHost(hostBuf);
  153.                         }
  154.                         break;
  155.  
  156.                     case 141:
  157.                         BCDdeClearHost();
  158.                         break;
  159.  
  160.                     case 200:
  161.                         PostQuitMessage(0);
  162.                         return 0;
  163.                 }
  164.  
  165.                 return 0;
  166.             }
  167.             break;
  168.  
  169.         case WM_DESTROY:
  170.             // And we are out of here!
  171.             PostQuitMessage(0);
  172.             return 0;
  173.     }
  174.  
  175.     // Call DefProc
  176.     return DefWindowProc(hWnd, msg, wParam, lParam);
  177. }
  178.  
  179.